package fictional.GUI;

import java.io.IOException;

import org.jdesktop.application.Application;

import fictional.Common.GenderItem;
import fictional.Common.IBL;
import fictional.Common.PlaceItem;
import fictional.Common.Response;
import fictional.Common.SpeciesItem;
import fictional.Common.User;

public class AddNewUserTask extends DefaultTask{

	Login login;
	User user;
	String name = "";
	GenderItem gender;
	SpeciesItem species;
	String organizations = "";
	PlaceItem birthplace;
	String occupations = "";
	String superPowers = "";
	
	public AddNewUserTask(Application application) {
		super(application);
	}

	public void setTask(IBL BL, Login login, User user, String name, GenderItem gender, SpeciesItem species, String organizations, PlaceItem birthplace, String occupations, String superPowers)
	{
		this.BL = BL;
		this.login = login;
		this.user = user;
		this.name = name;
		this.gender = gender;
		this.species = species;
		this.organizations = organizations;
		this.birthplace = birthplace;
		this.occupations = occupations;
		this.superPowers = superPowers;
	}
	
    @Override
    protected Object doInBackground() throws IOException, InterruptedException
    {
        response = new Response();
        BL.insertNewUser(user, name, gender, species, organizations, birthplace, occupations, superPowers, response);
        
        if (response.isIs_Success())
        {
        	successMessage = "New user created successfully!";
        	isSuccessMessageNeeded = true;
        	login.setNewUseDisplay(user.getUsername(), user.getPassword());
        }
        else
        {
        	errorTitle = "Error Creating New User";
        }
        
        return null;
    }
}
